home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************/
- /* Calculation of π by James Gregory (ca. 1671) approximation */
- /* π = 4 { 1 - 1/3 + 1/5 - 1/7 + 1/9 ... +[(-1)**n]/[2*k+1] ... } */
- /* */
- /* */
- /* M\Cooper */
- /* 3425 Chestnut Ridge Rd. */
- /* Grantsville, MD 21536 */
- /* ------------------------- */
- /* email: thegrendel@aol.com */
- /* */
- /* 06/91 */
- /* Source code placed in the public domain */
- /**************************************************************************/
-
- #include <stdio.h>
-
- #define MAX 5000
-
- void main()
- {
- double intermediate_result = 0,
- numerator,
- Pi;
- register int k;
-
-
-
-
- for( k = 0; k <= MAX; k++ )
- {
- if( k % 2 )
- numerator = -1.0;
- else numerator = 1.0;
-
- intermediate_result += numerator / ( 2 * (double)k + 1 );
- Pi = 4.0 * intermediate_result;
-
- printf( "Term #%5d ------> π ≈ %f \n", k, Pi );
- }
-
- }
-
-
-
-
-